// pages/login/login.js
const app = getApp()

Page({
  data: {
    name: ''
  },
  onLoad: function (options) {

  },
  bindKeyInput: function (e) {
    this.setData({
      name: e.detail.value
    })
  },
  login: function (e) {
    var self = this;
    wx.login({
      success: res => {
        console.log(res.code)
        wx.request({
          url: app.globalData.baseUrl + 'users/login',
          data: {
            code: res.code,
            name: self.data.name
          },
          method: "POST",
          success: function (res) {
            if (res.data.code == '000000') {
              wx.setStorageSync('session', res.data.uuid)
              wx.redirectTo({
                url: '../index/index'
              })
            }
          }
        })
      }
    })
  }
})